""" GameTimer module provides corresponding class with usefull functionality """

from time import time as getTime

class GameTimer:
    __slots__ = ('_start', '_isStarted', '_delay')

    def __init__(self, delay = None, start = False):
        self._start = 0
        self._isStarted = False
        self._start
        self._delay = delay

        if start:
            self.start()

    def start(self, delay = None):
        self._start = getTime()
        self._isStarted = True
        self._delay = delay

    def isStarted(self):
        if self._delay is not None:
            self.expired()
        return self._isStarted

    def stop(self):
        self._isStarted = False

    def time(self):
        return getTime() - self._start

    def restart(self):
        self.start(self._delay)

    def expired(self, timeSec = None, restart = False):
        if timeSec is None:
            assert self._delay is not None
            timeSec = self._delay

        if self.time() < timeSec:
            return False

        if restart:
            self.restart()
        else:
            self._isStarted = False
            
        return True

